<template>
  <div class="header-user">
    <el-popover placement="top-start" width="50" trigger="hover">
      <div class="popover-user">{{ loginUser.username }}</div>
      <div class="popover-item" @click="toSource">
        <img class="gitee-icon" :src="giteeImgUrl" />源码
      </div>
      <div class="popover-item" @click="toFront">前台展示</div>
      <div class="popover-item" @click="toBack">后台管理</div>

      <div class="popover-item" @click="handleLogout">退出</div>
      <div class="popover-button" slot="reference">
        <img class="header-icon" :src="userImgUrl" />
      </div>
    </el-popover>
  </div>
</template>

<script>
import { GetUserInfo } from '@/api/user';
export default {
  name: 'headerUser',
  data () {
    return {
      userImgUrl: require("@/assets/user.png"),
      giteeImgUrl: require("@/assets/gitee.png"),
      loginUser: { username: "", userid: "" },
    }
  },
  methods: {

    toBack () {
      this.$router.push("/management")
    },
    toSource () {
      window.open('https://gitee.com/jlk1912/CompanyManageAPI')
    },
    toFront () {
      this.$router.push("/front")
    },
    handleLogout () {
      localStorage.removeItem('authorization');
      this.$router.push("/login")
    }

  },
  mounted () {
    let token = localStorage.getItem("authorization");
    var user = GetUserInfo(token);
    user.then((result) => {
      console.log(this.loginUser);
      this.$set(this.loginUser, "username", result.data[0].username)
    });
  },

}
</script>

<style scoped>
.header-user {
  top: 10px;
  right: 20px;
  position: absolute;
}
.header-user img {
  height: 40px;
  vertical-align: middle;
}

.gitee-icon {
  height: 20px;
  vertical-align: middle;
  margin-right: 5px;
}
.popover-user {
  line-height: 35px;
  padding-left: 10px;
}

.popover-item {
  line-height: 35px;
  padding-left: 10px;
}

.popover-item:hover {
  color: white;
  cursor: pointer;
  background-color: rgb(1, 127, 255);
}

.popover-button {
  margin-right: 30px;
  margin-left: 10px;
  display: inline-block;
  color: white;
  text-shadow: 0.1em 0.1em 0.3em #333333;
}
.el-popover {
  min-width: 100px !important;
}
img.header-icon:hover {
  transform: rotate(360deg);
  -webkit-transform: rotate(360deg);
  -moz-transform: rotate(360deg);
  -o-transform: rotate(360deg);
  -ms-transform: rotate(360deg);
  transition: all 1s ease-in 0ms;
}
</style>

<style>
.el-header,
.el-footer {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  background-color: #d3dce6;
  color: #333;

  line-height: 200px;
  height: calc(100vh - 60px);
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  text-align: center;
  /* line-height: 160px; */
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
.el-popover {
  padding: 0px;
}
</style>